﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using gheat;

namespace VisualTest.Data
{
    public class InMemoryCache : ICacheService
    {
        public T Get<T>(string cacheID, Func<T> getItemCallback) where T : class
        {
            T item = HttpRuntime.Cache.Get(cacheID) as T;
            if (item == null)
            {
                item = getItemCallback();
                HttpContext.Current.Cache.Insert(cacheID, item);
            }
            return item;
        }
    }

    interface ICacheService
    {
        T Get<T>(string cacheID, Func<T> getItemCallback) where T : class;
    }

    public static class DataGateway
    {
        public static PointManager GetPoints()
        {
            PointManager p = new PointManager();

            EarthQuakesDataContext db = new EarthQuakesDataContext();

            var qm = (from q in db.QUAKES
                      where q.Year == 2000
                      select new { Latitude = q.Latitude, Longitude = q.Longitude, Magnitude = q.Magnitude }).ToList();

            foreach (var q in qm)
            {
                p.AddPoint(
                    new GMap.NET.PointLatLng(
                        Double.Parse(q.Latitude.Value.ToString()),
                        Double.Parse(q.Longitude.Value.ToString()),
                        "lol data",
                        decimal.Parse(q.Magnitude.ToString())
                        ));
            }

            return p;
        }
    }
}